<?php

namespace App\Console\Commands;

use App\Jobs\Notification;
use App\Library\ChargeCache;
use App\Service\NotificationService;
use App\Service\StationService;
use Illuminate\Console\Command;

class NotificationStationStatus extends Command
{
    use ChargeCache;

    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'push_status';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        A:
        sleep(8);
        //推送状态
        $station = (new StationService())->getStation()['StationInfos'];
        foreach ($station as $item) {
            foreach ($item['EquipmentInfos'] as $equipmentInfo) {
                foreach ($equipmentInfo['ConnectorInfos'] as $value) {
                    $res = $this->getChargeStatusCache($value['ConnectorID']);
                    if (!empty($res)) {
                        $res = json_decode($res, true);
                        if (!empty($res) && $res['status'] == 2) {
                            //推送状态
                            (new NotificationService())->notification_stationStatus($value['ConnectorID'],3);
                        }
                    }

                }
            }
        }
        echo "执行成功!" . date('Y-m-d H:i:s') . PHP_EOL;
        goto A;
    }
}
